
/* GCSx
** DATATYPE.H
**
** Basic data types and structures, and simple data-type conversion
*/

/*****************************************************************************
** Copyright (C) 2003-2006 Janson
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

#ifndef __GCSx_DATATYPE_H_
#define __GCSx_DATATYPE_H_

// Because SDL_Rect uses 16bit numbers which are too small for some purposes
struct Rect {
  Sint32 x, y;
  Sint32 w, h;
};

// Number of Uint32s to use for a void* (for bytecode)
extern int vPtrSize;

// Floating point type used for bytecode
// Also, printf code that displays it, and lib function to convert it
typedef float BCfloat;
#define BC_FLOAT_PRINTF "f"
#define BC_FLOAT_CONVERT strtof
/*
typedef double BCfloat;
#define BC_FLOAT_PRINTF "f"
#define BC_FLOAT_CONVERT strtod

typedef long double BCfloat;
#define BC_FLOAT_PRINTF "Lf"
#define BC_FLOAT_CONVERT strtold
*/

// Number of Uint32s to use for it
extern int bcFloatSize;

// Blank constant string
extern const std::string blankString;

// Converts between integers/floats and strings
// You must use string return values immediately! (buffer is overwritten each time)
// (NOT THREAD SAFE)
const char* intToStr(long value);
const char* floatToStr(BCfloat value);
long strToInt(const std::string& value);
BCfloat strToFloat(const std::string& value);

// Throws 1 if junk at end of string, 2 if entire string is unconvertable
long strToIntErr(const std::string& value) throw_int;

// printf for string class; limited to 255 characters at this time
// (NOT THREAD SAFE)
std::string formatString(const char* format, ...);

// Copies data from one matrix (layer, etc.) to another
// All sizes in bytes
// Works with sizes of 0; does NOT work with overlapping buffers
// @TODO: matrixSwap? (mostly for Undo)
void matrixCopy(const void* source, void* dest, int w, int h, int sourcePitch, int destPitch);

// Fills a Uint32 array (like memset but 32bit)
void memSet32(Uint32* dest, Uint32 value, int size);

// Not all platforms have stricmp
int myStricmp(const char* a, const char* b);
void toLower(std::string& str);

// Allocates a char[] to match the given string
char* newCpCopy(const std::string& fromStr);

// Used in hashes or maps that key off const char*
struct hash_eqstr {
    bool operator() (const char* s1, const char* s2) const {
        return (strcmp(s1, s2) == 0);
    }
};
struct map_ltstr {
    bool operator() (const char* s1, const char* s2) const {
        return (strcmp(s1, s2) < 0);
    }
};

#endif
